from typing import List, Optional
from datetime import datetime
import secrets

from fastapi import HTTPException
from sqlalchemy.orm import Session, Query

from app.db.session import get_db
from app.models.ai import AIConfig


class AIConfigService:
    """单例"""
    ai_config_list: List[AIConfig]=[]

    def __init__(self):
        self.load_config_list()

    def load_config_list(self):
        db:Session=next(get_db())
        self.ai_config_list = db.query(AIConfig).all()

    def get_ai_config_by_config_key(self,config_key:str)->Optional[AIConfig]:
        for config in self.ai_config_list:
            if config.config_key==config_key:
                return config
        return None




aiConfigService=AIConfigService()